package com.auth.sdk.transmit;

import com.alibaba.fastjson.JSON;
import com.auth.sdk.Headers;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.SneakyThrows;

/**
 * Feign inject interceptor
 *
 * @description: feign 客户端向下传递请求头参数
 * @author: cyj
 * @date 2022 -01-12 14:55:58
 *
 *
 */
public class FeignLonginContextTransmit extends RemoteLonginContextTransmitAbstract<RequestTemplate> implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        contextTransmit(requestTemplate, () -> {});
    }
    @Override
    public void setLonginContext(RequestTemplate requestTemplate) {
        requestTemplate.header(Headers.USER_NAME, LoginContextHolder.getLoginName());
        requestTemplate.header(Headers.USER_ID, LoginContextHolder.getLoginId());
        requestTemplate.header(Headers.ROLES, JSON.toJSONString(LoginContextHolder.getLoginRoles()));
        requestTemplate.header(Headers.AUTHS, JSON.toJSONString(LoginContextHolder.getLoginAuths()));
    }
}
